extends Base1
@export var attack_radius = 50.0 # 攻击区域半径
@export var detection_radius = 200.0 # 侦察区域半径
var start_position
var end_position
var random=RandomNumberGenerator.new()
var player_position = Vector2()
var RUN_SPEED=50.00
var patrol_points = [Vector2(100, 100), Vector2(300, 100)] # Example patrol points
var current_patrol_point = 0
var delta=get_physics_process_delta_time()
@export var limit=0.5
@export var endPoint:Marker2D
@onready var animated = $"../../Graphics/AnimatedSprite2D"
@onready var monster = $"../.."

func enter():
	animated.play("left")
	
	pass

func do():
	if player_position != Vector2.ZERO:
		get_parent().change_state(1)
	else:
		patrol(delta)
	monster.move_and_slide()
	pass

func patrol(delta):
	var direction = (patrol_points[current_patrol_point] - monster.position).normalized()
	monster.position += direction * RUN_SPEED * delta
	monster.velocity=direction*RUN_SPEED
	if monster.position.distance_to(patrol_points[current_patrol_point]) < 10:
		current_patrol_point = (current_patrol_point + 1) % patrol_points.size()

func _on_attack_area_body_entered(body):
	if body.is_in_group("player"):
		player_position = body.global_position  # 获取玩家位置作为全局变量
	pass

func changeDirection():
	var temEnd=end_position
	end_position=start_position
	start_position=temEnd

func move():
	pass
